package com.shycloud.mido.homework.thread;
import java.time.LocalDate;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import com.shycloud.mido.common.core.util.SpringContextHolder;
import com.shycloud.mido.homework.api.vo.HomeworkDashboardReqVO;
import com.shycloud.mido.homework.api.vo.HomeworkDashboardRespVO;
import com.shycloud.mido.homework.pattern.HomeworkDashboardRuleFactory;
import com.shycloud.mido.homework.pattern.IHomeworkDashboardRule;
import lombok.extern.slf4j.Slf4j;
/**
 * 线程处理
 * @author bard.bai
 *
 */
@Slf4j
public class HomeworkStatusThreadV2 implements Runnable {

	private LocalDate startDate;
    private HomeworkDashboardReqVO vo;
    private Map<LocalDate, HomeworkDashboardRespVO> resultMap;
    private Semaphore semaphore;
    private CountDownLatch countDownLatch;

    public HomeworkStatusThreadV2(LocalDate startDate,HomeworkDashboardReqVO vo,Map<LocalDate, HomeworkDashboardRespVO> resultMap, Semaphore semaphore,
            CountDownLatch countDownLatch) {
    	this.startDate = startDate;
        this.vo = vo;
        this.resultMap = resultMap;
        this.semaphore = semaphore;
        this.countDownLatch = countDownLatch;
    }

   
    @Override
    public void run() {
        try {
            semaphore.acquire();
            HomeworkDashboardRuleFactory homeworkDashboardRuleFactory = SpringContextHolder.getBean(HomeworkDashboardRuleFactory.class);
            IHomeworkDashboardRule rule = homeworkDashboardRuleFactory.getBeanRule(vo);
            rule.getViewDatas(startDate,vo,resultMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            semaphore.release();
            countDownLatch.countDown();
        }

    }
    
}